﻿using OperationPlugins;
using OperationPlugins.Validators;
using TimeProject.Engine;
using TimeProject.Engine.DbContent;
using TimeProject.Engine.DbModels;

namespace TimeProject.Validators.DbModels.Level3
{
    [ValidatorOf(ValidationLevel.Level3, typeof(UserActivity))]
    [OperationFilter(TimeProjectOperations.Login)]
    [OperationFilter(TimeProjectOperations.Register)]
    public class UserActivityValidator : TimeProjectValidatorBase<UserActivity>
    {
        protected override void Validate()
        {
            if (Value.Type == UserActivityType.Login)
            {
                User user = Db.GetUser(Value.UserId);

                var latest = Db.GetLatestLogin(Value.UserId);
                if (latest == null)
                {
                    Raise("Hello {0}! Welcome to using Time:Project!", user.FullName);
                }
            }
        }
    }
}
